﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace QL_BenXe
{
    public partial class frm_SearchLichXeChay : Form
    {
        public frm_SearchLichXeChay()
        {
            InitializeComponent();
        }

        private void frm_SearchLichXeChay_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            cmb_TuyenDuong.DisplayMember = "TenTuyenDuong";
            cmb_TuyenDuong.ValueMember = "MaTuyenDuong";
            cmb_TuyenDuong.DataSource = TuyenDuongBUS.Select_All();

            cmb_Xe.DisplayMember = "BienSo";
            cmb_Xe.ValueMember = "MaXe";
            cmb_Xe.DataSource = XeBUS.Select_All();

            cmb_TaiChinh.DisplayMember = "TenNhanVien";
            cmb_TaiChinh.ValueMember = "MaNhanVien";
            cmb_TaiChinh.DataSource = NhanVienBUS.Select_TaiXe();

            cmb_TaiPhu.DisplayMember = "TenNhanVien";
            cmb_TaiPhu.ValueMember = "MaNhanVien";
            cmb_TaiPhu.DataSource = NhanVienBUS.Select_TaiXe();

            cmb_TiepVien.DisplayMember = "TenNhanVien";
            cmb_TiepVien.ValueMember = "MaNhanVien";
            cmb_TiepVien.DataSource = NhanVienBUS.Select_TiepVien();
        }

        private void btn_Search_Click(object sender, EventArgs e)
        {
            try
            {
                dtg_LichXeChay.AutoGenerateColumns = false;
                LichChay emp = new LichChay();
                emp.BienSo = cmb_Xe.Text;
                emp.TenTuyenDuong = cmb_TuyenDuong.Text;
                emp.Ngay = dateTimePicker1.Value.ToShortDateString();
                if (!txt_Gio.Text.Equals(""))
                {
                    emp.GioXuatBen = txt_Gio.Text;
                    if (!txt_Phut.Text.Equals(""))
                        emp.GioXuatBen += ":" + txt_Phut.Text;
                }
                emp.TenTaiChinh = cmb_TaiChinh.Text;
                emp.TenTaiPhu = cmb_TaiPhu.Text;
                emp.TenTiepVien = cmb_TiepVien.Text;
                List<LichChay> list=LichChayBUS.Search(emp);
                if (list.Count != 0)
                    dtg_LichXeChay.DataSource = list;
                else
                    MessageBox.Show("Không tìm thấy kết quả nào");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
